package cn.lcfms.cms.model;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.lcfms.bin.service.BaseService;
import cn.lcfms.cms.CmsDataBase;
import cn.lcfms.utils.Page;
import cn.lcfms.utils.StringUtils;

public class GetNewsByid extends CmsDataBase{

	public GetNewsByid(HttpServletRequest request, HttpServletResponse response, int id, BaseService service) {
		super(request, response, id, service);
	}

	@Override
	public void data() {
		service.setTable("articles").column("id","title","desc");
		service.where("category_id=#{category_id}");
		service.setData(id);
		int page=StringUtils.StringToInteger(request.getParameter("page"), 1);
		List<HashMap<String, Object>> list = service.selectPage(10, page);
		request.setAttribute("list", list);
		if(list.size()>0) {
			Long count=(Long)list.get(0).get("count");
			Page obj=new Page(count.intValue(), 10, 5, request);
			request.setAttribute("page", obj);
		}	
		HashMap<String, Object> map = service.setTable("categories").column("id","pid","title").where("id="+id).selectMap();
		request.setAttribute("menu_title_1", map);
		int topid=(int) map.get("pid");
		if(topid!=0) {
			HashMap<String, Object> kap = service.column("id","pid","title").where("id="+topid).selectMap();
			request.setAttribute("menu_title_0", kap);
		}		
	}
}
